package main

import (
	"fmt"
	"path/filepath"

	"demserver/src/elevation"
)

func main() {
	// Use the actual GeoTIFF file
	filename := "./demdata/ClipResult.tif"

	// Get absolute path to the file
	absPath, err := filepath.Abs(filename)
	if err != nil {
		fmt.Printf("Failed to get absolute path: %v\n", err)
		return
	}

	fmt.Printf("Loading GeoTIFF file: %s\n", absPath)
	geoTiff, err := elevation.LoadGeoTIFF(absPath)
	if err != nil {
		fmt.Printf("Failed to load GeoTIFF: %v\n", err)
		return
	}
	fmt.Println("GeoTIFF loaded successfully")

	// Test with one coordinate
	lat := 31.02659757575758
	lon := 103.54607363636364
	expected := 780.2126995110525

	x, y, err := geoTiff.LatLonToPixel(lat, lon)
	if err != nil {
		fmt.Printf("Failed to convert coordinates (%f, %f): %v\n", lat, lon, err)
		return
	}

	fmt.Printf("Lat: %f, Lon: %f\n", lat, lon)
	fmt.Printf("Pixel coordinates: X=%f, Y=%f\n", x, y)

	// Get elevation value
	elevationVal, err := geoTiff.GetElevation(x, y)
	if err != nil {
		fmt.Printf("Failed to get elevation at (%f, %f): %v\n", x, y, err)
		return
	}

	fmt.Printf("Expected elevation: %f\n", expected)
	fmt.Printf("Actual elevation: %f\n", elevationVal)
	fmt.Printf("Difference: %f\n", elevationVal-expected)
}
